<template>
  <!-- 工具栏 -->
  <el-row :gutter="10" class="mb8">
    <el-col :span="1.5">
      <el-button
        type="primary"
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        v-hasPermi="['transport:list:add']"
      >新增</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="success"
        icon="el-icon-edit"
        size="mini"
        :disabled="single"
        @click="handleUpdate"
        v-hasPermi="['transport:list:edit']"
      >修改</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="danger"
        icon="el-icon-delete"
        size="mini"
        :disabled="multiple"
        @click="handleDelete"
        v-hasPermi="['transport:list:remove']"
      >删除</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="info"
        icon="el-icon-upload2"
        size="mini"
        @click="handleImport"
        v-hasPermi="['transport:list:import']"
      >导入</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="warning"
        icon="el-icon-download"
        size="mini"
        @click="handleExport"
        v-hasPermi="['transport:list:export']"
      >导出</el-button>
    </el-col>
    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  </el-row>
</template>

<script>
  import { listTransport,listIsoUnit,getTransport,delTransport,addAndUpdateTransport,importTemplate,exportTransport,addTransport,updateTransport } from "@/api/erp/transport/transport";
  import { isArray } from '../../../../utils/validate'
  import { getToken } from "@/utils/auth";
  export default {
    name: 'trTools',
    props:{
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //必要参数
      ids:Array
    },
    data(){
      return{
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/transport/importData"
        },
        addOrEit:{
          ids:[],
          open :false,
          single:false,
          form:{},
          title:"",
          multiple:false,
        },
        // 显示搜索条件
        showSearch: false,
        // // 非单个禁用
        // single: true,
        // // 非多个禁用
        // multiple: true
      }
    },
    created() {
      // this.getList();
    },
    watch:{
      showSearch:function(val) {
        this.$emit("getSearch", !this.showSearch);
      },
    },
    methods: {
      /** 添加按钮操作 */
      handleAdd() {
        this.addOrEit.open = true;
        this.addOrEit.title = "添加运输单位类型";
        this.$emit("addOrEit", this.addOrEit);
      },
      /** 修改按钮操作 */
      handleUpdate() {
        // this.reset();
        const id = this.ids;
        getTransport(id).then(response => {
          this.addOrEit.form = response.data;
          this.addOrEit.open = true;
          this.title = "修改运输单位类型";
          this.$emit("update:addOrEit", this.addOrEit);
        });

      },
      /** 删除按钮操作 */
      handleDelete() {
        const ids =  this.ids;
        var str = "";
        if(ids.length>0&&ids.length<=3){
          str = '是否确认删除运势单位类型为"' + ids + '"的数据项?';
        }else if(ids.length>=4){
          str = '是否确认删除选择的"' + ids.length + '"项运输单位类型数据?';
        }else{
          str ='是否确认删除所有数据';
        }
        this.$confirm(str, "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTransport(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "用户导入";
        this.upload.open = true;
        this.$emit("update:upload", this.upload);
      },
      /** 导出按钮操作 */
      handleExport() {
        const ids = this.ids;
        var str = "";
        if(ids.length>0&&ids.length<=3){
          str = '是否确认导出运势单位类型为"' + ids + '"的数据项?';
        }else if(ids.length>=4){
          str = '是否确认导出选择的"' + ids.length + '"项运输单位类型数据?';
        }else{
          str ='是否确认导出所有数据';
        }
        this.$confirm(str, "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTransport(ids);
        }).then(response => {
          this.download(response.msg);
        })
      },
      /** 搜索按钮操作 */
      getList() {
        // this.$emit("update:showSearch", !this.showSearch);
        this.$emit("getList",true);
      }
    }
  }
</script>

<style scoped>

</style>
